package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2018/12/18 17:34
 * @description
 */
public class Code890 {
    public static void main(String[] args) {
        new Code890().findAndReplacePattern(null, "acc");
    }

    public List<String> findAndReplacePattern(String[] words, String pattern) {
        List<String> result = new ArrayList<>();
        String newPattern = getNewStr(pattern.toLowerCase(), 'A');
        for (String word : words) {
            if (getNewStr(word.toLowerCase(), 'A').equals(newPattern)) {
                result.add(word);
            }
        }
        return result;
    }

    private String getNewStr(String str, char start) {
        for (char c : str.toCharArray()) {
            if (c >= 'a' && c <= 'z') {
                str = str.replace(c, start);
                return getNewStr(str, (char)(start + 1));
            }
        }
        return str;
    }
}
